import Vue from "vue";
import Router from "vue-router";
import Login from "./views/Login.vue";
import {
  isLogin
} from "./utils/isLogin";

Vue.use(Router);

let routerConfig = {
  mode: "history",
  base: process.env.BASE_URL,
  routes: [{
      path: "/",
      component: Login
    },
    {
      path: "/container",
      component: () =>
        import( /* webpackChunkName: "container" */ "./views/Content.vue"),
      children: [{
          path: "/",
          redirect: process.env.VUE_APP_USER === "true" ? "userList" : "manageToken"
        },
        {
          path: "userList",
          component: () =>
            import(
              /* webpackChunkName: "userList" */
              "./views/UserManage/UserList.vue"
            )
        },
        {
          path: "ident-audit",
          component: () =>
            import(
              /* webpackChunkName: "ident-audit" */
              "./views/UserManage/IdentAudit.vue"
            )
        },
        {
          path: "fastToken",
          component: () =>
            import(
              /* webpackChunkName: "fastToken" */
              "./views/FastToken/FastToken.vue"
            )
        },
        {
          path: "banner",
          component: () =>
            import(
              /* webpackChunkName: "banner" */
              "./views/Explorer/Banner.vue"
            )
        },
        {
          path: "category",
          component: () =>
            import(
              /* webpackChunkName: "category" */
              "./views/Explorer/Category.vue"
            )
        },
        {
          path: "application",
          component: () =>
            import(
              /* webpackChunkName: "application" */
              "./views/Explorer/Application.vue"
            )
        },
        {
          path: "withdrawAudit",
          component: () =>
            import(
              /* webpackChunkName: "withdrawAudit" */
              "./views/AssetsManage/WithdrawAudit.vue"
            )
        },
        {
          path: "withdrawRecord",
          component: () =>
            import(
              /* webpackChunkName: "withdrawRecord" */
              "./views/AssetsManage/WithdrawRecord.vue"
            )
        },
        {
          path: "withdrawConfig",
          component: () =>
            import(
              /* webpackChunkName: "withdrawConfig" */
              "./views/AssetsManage/WithdrawConfig.vue"
            )
        },
        {
          path: "accMonitor",
          component: () =>
            import(
              /* webpackChunkName: "accMonitor" */
              "./views/AssetsManage/AccMonitor.vue"
            )
        },
        {
          path: "transactionRecord",
          component: () =>
            import(
              /* webpackChunkName: "transactionRecord" */
              "./views/AssetsManage/TransactionRecord.vue"
            )
        },
        {
          path: "announcement",
          component: () =>
            import(
              /* webpackChunkName: "Announcement" */
              "./views/Message/Announcement.vue"
            )
        },
        {
          path: "flashChange",
          component: () =>
            import(
              /* webpackChunkName: "flashChange" */
              "./views/FlashChange/TokenManage.vue"
            )
        },
        {
          path: "manageToken",
          component: () =>
            import(
              /* webpackChunkName: "tokens" */
              "./views/CoinsManage/CoinsList.vue"
            )
        },
        {
          path: "starCoin",
          component: () =>
            import(
              /* webpackChunkName: "starCoin" */
              "./views/CoinsManage/StarCoin.vue"
            )
        },
        {
          path: 'feeConfig',
          component: () =>
            import(
              /* webpackChunkName: "feeConfig" */
              "./views/CoinsManage/FeeConfig.vue"
            )
        },
        {
          path: "warehouse",
          component: () =>
            import(
              /* webpackChunkName: "starCoin" */
              "./views/CoinsManage/CoinsBase.vue"
            )
        },
        {
          path: 'starCoinCategory',
          component: () =>
            import(
              /* webpackChunkName: "coinCategory" */
              "./views/CoinsManage/CoinCategory"
            )
        },
        {
          path: 'parallelManage',
          component: () =>
            import(
              /* webpackChunkName: "parallelManage" */
              "./views/WalletManage/ParallelManage.vue"
            )
        },
        {
          path: 'walletList',
          component: () =>
            import(
              /* webpackChunkName: "walletList" */
              "./views/WalletManage/WalletList.vue"
            )
        },
        {
          path: 'legalCoin',
          component: () =>
            import(
              /* webpackChunkName: "legalCoin" */
              "./views/WalletManage/LegalCoin.vue"
            )
        },
        {
          path: 'log',
          component: () =>
            import(
              /* webpackChunkName: "LogList" */
              "./views/LogManage/LogList"
            )
        },
        {
          path: 'news',
          component: () =>
            import(
              /* webpackChunkName: "news" */
              "./views/NewsManage/News"
            )
        },
        {
          path: 'article',
          component: () =>
            import(
              /* webpackChunkName: "article" */
              "./views/NewsManage/Article"
            )
        },
        {
          path: 'callfree',
          component: () =>
            import(
              /* webpackChunkName: "article" */
              "./views/Dapp/CallFree.vue"
            )
        },
        {
          path: 'carTeam',
          component: () =>
            import(
              /* webpackChunkName: "carTeam" */
              "./views/CarTeam/LeaderAudit.vue"
            )
        },
        {
          path: 'editPassword',
          component: () =>
            import(
              /* webpackChunkName: "editPassword" */
              "./views/System/EditPassword.vue"
            )
        },
        {
          path: 'liveAudit',
          component: () =>
            import(
              /* webpackChunkName: "liveAudit" */
              "./views/Live/LiveAudit.vue"
            )
        },
        {
          path: 'liveCategory',
          component: () =>
            import(
              /* webpackChunkName: "liveCategory" */
              "./views/Live/LiveCategory.vue"
            )
        },
        {
          path: 'liveName',
          component: () =>
            import(
              /* webpackChunkName: "liveName" */
              "./views/Live/LiveNameAudit.vue"
            )
        },
        {
          path: 'liveBanner',
          component: () =>
            import(
              /* webpackChunkName: "liveBanner" */
              "./views/Live/LiveBanner.vue"
            )
        },
        {
          path: 'totalBalance',
          component: () =>
            import(
              /* webpackChunkName: "totalBalance" */
              "./views/AssetsManage/TotalBalance.vue"
            )
        },
        {
          path: 'managers',
          component: () =>
            import(
              /* webpackChunkName: "managers" */
              "./views/System/Managers.vue"
            )
        },
        {
          path: 'parallelSupported',
          component: () =>
            import(
              /* webpackChunkName: "parallelSupported" */
              "./views/WalletManage/ParallelSupported.vue"
            )
        },
        {
          path: 'PriceSet',
          component: () =>
            import(
              /* webpackChunkName: "coinPrice" */
              "./views/CoinsManage/CoinPrice.vue"
            )
        },
        {
          path: 'gas',
          component: () =>
            import(
              /* webpackChunkName: "DecFeeConfig" */
              "./views/CoinsManage/DecFeeConfig.vue"
            )
        }
      ]
    }
  ]
};

let router = new Router(routerConfig);

router.beforeEach((to, from, next) => {
  if (!isLogin() && to.path != "/") {
    return next({
      path: '/',
      replace: true
    });
  }
  next();
});

router.afterEach(() => {
  window.scrollTo(0, 0);
});

export default router;